package com.carrot.newsgallery.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carrot.newsgallery.common.R;
import com.carrot.newsgallery.entity.NewsFavor;
import com.carrot.newsgallery.service.NewsFavorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api("论坛主题内容")
@RequestMapping("/forum")
public class ForumController {

    @Autowired
    private NewsFavorService newsFavorService;

    @GetMapping("/{currentPage}/{pageSize}")
    @ApiOperation("按照最近公开时间时间顺序获取论坛内容")
    public R getByTime(@PathVariable int currentPage, @PathVariable int pageSize){
        LambdaQueryWrapper<NewsFavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(true,NewsFavor::getIsShared,1)
                .eq(true,NewsFavor::getIsBanned,0)
                .orderByDesc(NewsFavor::getPublicizeDate);
        Page<NewsFavor> page = new Page<>(currentPage,pageSize);
        return R.success(newsFavorService.page(page,lqw),"查询成功");
    }

}
